<div class="page-header">
    <h3>Payment History Of Student's Fees</h3>
</div>

<div class="row-fluid">
    <div class="span12">
        <h4>Filter</h4>
        <?php echo $this->Form->create('Query', array('id' => 'form-query', 'class' => 'form form-horizontal', 'inputDefaults' => array('label' => false,'div' => false)));?>
                <table class="table ">
                    <tr><td>Start Date</td><td>End Date</td><td>Session</td><td>Index Number</td><td>Fee Type</td></tr>
                    <tr>
                        <td>
                            <?php echo $this->Form->input('start_dt', array('id'=>'start_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_start_dt,'class' => 'input-medium','div' => false, 'label' => false));?>
                         </td>
                        <td>
                            <?php echo $this->Form->input('end_dt', array('id'=>'end_dt','placeholder' => 'yyyy-mm-dd', 'default'=>$default_end_dt,'class' => 'input-medium','div' => false, 'label' => false));?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('academic_session', array('id'=>'academic_session', 'options'=>$academic_sessions, 'default'=>$aca_ses, 'class' => 'input-medium','div' => false, 'label' => false));?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('index_no', array('id'=>'index_no','class' => 'input-medium','default'=>$index_no,'div' => false, 'label' => false));?>
                        <td>
                            <?php echo $this->Form->input('fee_type', array('id'=>'fee_type', 'options'=>$fee_types,'default'=>$default_fee_type,'class' => 'input-medium','div' => false, 'label' => false,));?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                            <div class="controls">
                                <button type="submit" id="re_query-btn" class="btn btn-primary">Re Query</button>
                                <button type="button"  id="print-btn" class="btn">Print</button>
                                <button type="button"  id="export-btn" class="btn">Export</button>
                            </div>
                        </td>
                    </tr>
                </table>
        <?php echo $this->Form->end();?>
        <style type="text/css">
            .table th {
                background: #b6b6b6;
                color: #fff;
            }
            .table th, .table td {
                padding: 2px;
                font-size: 12px;
            }
        </style>
        <div style="height: 400px; overflow: auto;">
            <table  class="table table-bordered" id="flex2">
                <thead>
                <tr><th>Date</th><th>Student Name</th><th>Index Number</th><th>Fee Type</th><th>Fee Code</th><th>Fee Amount GHc</th><th>Total Paid GHc</th><th>Balance GHc</th></tr>
                </thead>
                <tbody>
                <?php
                $tl_paid = 0;
                $tl_fee_amount = 0;
                $tl_bal = 0;
                foreach ($data_table as $obj) {
                    $paid = doubleval($obj['tl_credit_amount']) ;
                    $fee_amount = doubleval($obj['amount']);
                    $bal = doubleval($obj['balance']);

                    $tl_paid = $tl_paid + $paid;
                    $tl_fee_amount = $tl_fee_amount + $fee_amount;
                    $tl_bal = $tl_bal + $bal;
                    ?>
                    <tr>
                        <td><?php echo $obj['date'];?></td>
                        <td><?php echo $obj['name'];?></td>
                        <td><?php echo $obj['index_number'];?></td>
                        <td><?php echo $obj['description'];?></td>
                        <td><?php echo $obj['fee_code'];?></td>
                        <td><?php echo $controller->formatNumber($obj['amount'],'money');?></td>
                        <td><?php echo $controller->formatNumber($obj['tl_credit_amount'],'money');?></td>
                        <td><?php echo $controller->formatNumber($obj['balance'],'money');?></td>
                    </tr>
                    <?php
                    //}
                }
                if($tl_fee_amount > 0){
                    ?>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><strong>Totals</strong></td>
                        <td><strong><?php echo $controller->formatNumber($tl_fee_amount,'money');?></strong></td>
                        <td><strong><?php echo $controller->formatNumber($tl_paid,'money');?></strong></td>
                        <td><strong><?php echo $controller->formatNumber($tl_bal,'money');?></strong></td>
                    </tr>
                <?php
                }
                ?>
                </tbody>
            </table>
        </div>


        <form id="print-export-form" method="post" action="<?php echo $this->Html->url(array('controller' => 'Staff', 'action' => 'print_export_payment_history')); ?>" target="PrintExportWindow">
            <input type="hidden" name="data_type" id="data_type" value="" />
            <input type="hidden" name="data_start_dt" id="data_start_dt"  value="" />
            <input type="hidden" name="data_end_dt" id="data_end_dt"  value="" />
            <input type="hidden" name="data_fee_type" id="data_fee_type"  value="" />
            <input type="hidden" name="data_index_no" id="data_index_no"  value="" />
            <input type="hidden" name="data_session" id="data_session"  value="" />
        </form>
    </div>
</div>

<!--<input type="hidden" id="table-url" value="<?php /*echo $this->Html->url(array('controller' => 'Staff', 'action' => 'get_payment_history')); */?>" />-->

<?php
    echo $this->Html->script('staff/payment_history.js');
?>
